package com.steel.yfmall.cloud.assistant.user.impl;

import com.steel.yfmall.cloud.assistant.dto.para.user.ParaBusinessStaffInfo;
import com.steel.yfmall.cloud.assistant.po.user.BusinessStaffInfo;
import com.steel.yfmall.cloud.assistant.po.user.BusinessStaffInfoExample;
import com.steel.yfmall.cloud.assistant.user.BusinessStaffInfoService;
import com.steel.yfmall.cloud.assistant.user.mapper.BusinessStaffInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: BusinessStaffInfoServiceImpl
 * @Package com.steel.yfmall.cloud.assistant.user.impl
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/1/21 19:28
 */
@Slf4j
@Service
public class BusinessStaffInfoServiceImpl implements BusinessStaffInfoService {

    /**
     * @author 龙飞
     * @version 1.0
     * @since 2021/01/11 星期一 16:24
     */
    @Override
    public List<BusinessStaffInfo> selectByStaffCodeLimit1(String staffCode) {
        BusinessStaffInfoExample businessStaffInfoExample = new BusinessStaffInfoExample();
        businessStaffInfoExample.createCriteria().andStaffCodeEqualTo(staffCode);
        businessStaffInfoExample.limit(0, 1);
        return businessStaffInfoMapper.selectByExample(businessStaffInfoExample);
    }

    /**
     * 根据条件查询 企业业务员工信息
     * @Title: getBusinessStaffInfoByPara
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return com.steel.yfmall.cloud.assistant.po.user.BusinessStaffInfo    返回类型
     * @author yuchaohua
     * @date 2021/1/21 19:35
     */
    @Override
    public BusinessStaffInfo getBusinessStaffInfoByPara(ParaBusinessStaffInfo paraBean) {
        BusinessStaffInfoExample example = new BusinessStaffInfoExample();
        BusinessStaffInfoExample.Criteria criteria = example.createCriteria();
        getSearchData(criteria, paraBean);
        return businessStaffInfoMapper.selectOneByExampleSelective(example);
    }

    private void getSearchData(BusinessStaffInfoExample.Criteria criteria, ParaBusinessStaffInfo paraBean) {
        if (criteria == null || paraBean == null) {
            return;
        }
        // 员工编码
        if (StringUtils.isNotBlank(paraBean.getStaffCode())){
            criteria.andStaffCodeEqualTo(paraBean.getStaffCode());
        }
        // 部门
        if (StringUtils.isNotBlank(paraBean.getDepartment())){
            criteria.andDepartmentEqualTo(paraBean.getDepartment());
        }
        // 职位
        if (StringUtils.isNotBlank(paraBean.getPosition())){
            criteria.andPositionEqualTo(paraBean.getPosition());
        }
        // 业务销售组编码
        if (StringUtils.isNotBlank(paraBean.getSaleGroupCode())){
            criteria.andSaleGroupCodeEqualTo(paraBean.getSaleGroupCode());
        }
    }

    @Resource
    private BusinessStaffInfoMapper businessStaffInfoMapper;

}
